/**
 * 安卓白金英雄坛制作组 <br>
 * 文件名：ExchangeScreen.java <br>
 * 创建时间：2013-8-24 下午5:19:22 <br>
 * 所属项目：GmudEX <br>
 * @author 12548 <br>
 */
package lostland.gmud.exv2.ui;

import com.orhanobut.logger.Logger;

import lostland.gmud.exv2.Game;
import lostland.gmud.exv2.Gmud;
import lostland.gmud.exv2.MapScreen;
import lostland.gmud.exv2.data.Item;
import lostland.gmud.exv2.ui.core.YesNoScreen;

/**
 * 类名：ExchangeScreen <br>
 * 说明：普遍物品交换界面
 *
 * @author 12548
 */
public class ExchangeScreen extends YesNoScreen {
	boolean fail = true;
	int change, count, forwp;
	String s2;

	/**
	 * @param s
	 * @param instance
	 */
	public ExchangeScreen(String s, String s2, int change, int count, int forwp) {
		super(s);
		fail = false;
		this.change = change;
		this.count = count;
		this.forwp = forwp;
		this.s2 = s2;
		if (!fail && Gmud.mc.get_pile(Gmud.mc.findItem(change)) < count) {
			Logger.w("fail");
			fail = true;
//			game.popToRootScreen();
			return;
		}
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.DialogScreen#update(float)
	 */
	@Override
	public void update(float deltaTime) {
		if (!fail && Gmud.mc.get_pile(Gmud.mc.findItem(change)) < count) {
			Logger.w("fail");
			fail = true;
			getGame().popToRootScreen();
			return;
		}
		if (fail) {
			getGame().popToRootScreen();
			return;
		}
		super.update(deltaTime);
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.YesNoScreen#present(float)
	 */
	@Override
	public void present(float deltaTime) {
		if (fail) {
			MapScreen.getInstance().present(0);
			Game.getInstance().popToRootScreen();
			return;
		}
		super.present(deltaTime);
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.YesNoScreen#onYes()
	 */
	@Override
	protected void onYes() {
		Gmud.mc.drop(change, count);

		final Item item = Item.generateItem(forwp, Gmud.mc.luckness);
		Gmud.mc.give(item);
		new TalkingScreen(s2).replaceCurrent();
//		TalkingScreen.ts = new TalkingScreen(game, "你失去了" + Gmud.wp.get(change).getName() +
//											", 获得了" + Gmud.wp.get(forwp).getName(), false);
	}

	/* （非 Javadoc）
	 * @see lostland.gmud.exv2.ui.YesNoScreen#onNo()
	 */
	@Override
	protected void onNo() {
		getGame().popToRootScreen();
	}

}
